package com.bottle.webdemo;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

public class Ts {


    private static Toast toast;

    /**
     * @deprecated
     * @param context
     * @param text
     */
    public static void show(Context context, Object text) {
        show(text, Toast.LENGTH_SHORT);
    }
    public static void show(Object text) {
        show(text, Toast.LENGTH_SHORT);
    }


    private static void show(Object text, int duration) {
        Context  context = MyApplication.getApp();
        if (context == null || text == null) {
            return;
        }
        if (toast == null) {
            if (text instanceof String) {
                toast = Toast.makeText(context, (String) text, duration);
            }
            if (text instanceof Integer) {
                toast = Toast.makeText(context, (Integer) text, duration);
            }
        } else {
            if (text instanceof String) {
                toast.setText((String) text);
            }
            if (text instanceof Integer) {
                toast.setText((Integer) text);
            }
        }
        if (toast != null) {
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
    }
}
